<?php
include "required_code.php"; 
//include "db_connect.php";
if(isset($_POST["button"]) && $_POST['std_id']!="" && $_POST['std_password']!=""){
	//echo $_POST["std_id"];
	$query="SELECT * FROM students WHERE std_id=$_POST[std_id]";
	$db_result=db_query($query);
	$result=mysql_fetch_array($db_result);
	//echo $result['std_password'].$_POST["std_password"];
					///////////////////////////////////////////////////SESSION///////////////////////////////////////////////////
					
				if($result['std_id']==$_POST['std_id'] && $result['std_password']==$_POST['std_password']) {
						//	echo $test_item;
							session_start();
							$_SESSION['ses_user_id'] = session_id();
							$_SESSION['ses_std_id'] = $_POST['std_id'];
							echo "Authentication passed. <br>";
							$query2="SELECT * FROM std_progress WHERE std_id=$_POST[std_id]";
							$db_result2=db_query($query2);
							$result2=mysql_fetch_array($db_result2);
							//echo $result2['pretest_sts'];
							if($result2['pretest_sts']==1){
								echo "You are an existing user.";
								echo "<meta http-equiv='refresh' content='1;URL=progress.php' />";
							}
							else{
								echo "You are a new user.";
								echo "<meta http-equiv='refresh' content='1;URL=instruction.php' />";
							}
				}
				else {
							echo "Authentication failed";
							echo "<meta http-equiv='refresh' content='1;URL=index.php' />";
				}
				
				///////////////////////////////////////////////////SESSION///////////////////////////////////////////////////
}
		else {
							echo "Authentication failed";
							echo "<meta http-equiv='refresh' content='1;URL=index.php' />";
				}
?>